#include <opencv2\opencv.hpp>
#include <iostream>

using namespace cv;

int test02(int argc, char** argv)
{
    char* imageName = (argc == 2) ? argv[1] : "C:\\ProgramsOrTools\\OpenCV2.4.3\\samples\\cpp\\lena.jpg";

    Mat image;
    image = imread(imageName, 1);
    if (!image.data)
    {
        printf("No image data");
        return -1;
    }

    Mat gray_image;
    cvtColor(image, gray_image, CV_RGB2GRAY);

    //Mat copy_gray_image_part;
    //{
    //    Mat gray_image_part(gray_image, Rect(10,10,100,100));
    //    namedWindow("gray_part", CV_WINDOW_NORMAL);

    //    copy_gray_image_part= gray_image_part.clone();
    //}
    //imshow("gray_part", copy_gray_image_part);
    //waitKey(0);

    imwrite("lena_gray.jpg", gray_image);

    namedWindow(imageName, CV_WINDOW_NORMAL);
    namedWindow("gray", CV_WINDOW_NORMAL);

    imshow(imageName, image);
    imshow("gray", gray_image);

    waitKey(0);
    return 0;
}
